﻿using System.IO;
using System.Reflection;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

namespace XamlInspector.Foundation
{
    public static class EmbeddedResourceProvider
    {
        private static readonly Assembly _assembly;

        static EmbeddedResourceProvider()
        {
            _assembly = typeof (EmbeddedResourceProvider).GetTypeInfo().Assembly;
        }

        public static ImageSource GetImage(string path)
        {
            using (Stream stream = _assembly.GetManifestResourceStream("XamlInspector.Assets." + path))
            {
                var source = new BitmapImage();
                source.SetSourceAsync(stream.AsRandomAccessStream());
                return source;
            }
        }

        public static string GetFile(string path)
        {
            using (Stream stream = _assembly.GetManifestResourceStream("XamlInspector.Assets." + path))
            {
                using (var reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
        }
    }
}
